function setUp(){
	
	PicBoard.getTranslations(['lang_321_confirmDeleteBook', 'lang_322_donateConfirm', 'lang_51_yes', 'lang_52_no'], function(){});
			
	$('#controlArea').css({
		'margin-top': '27px',
		'height': $('#UserResultArea').height() 
	});

	// Bind buttons
	
	$('#saveEdits').bind('click', function(){
		// Clicking the save button should send the gID, group name and description to the server and wait for a response.
		$.post(PicBoard.baseURL + "rsrc.php?req=updateChart", { chartID: $('input#chID').val(), name: $('input#groupName').val(), description: $('textarea#groupDescription').val() }, function(data){
			if(data.statusCode == 200){
				alert(data.message);
			} else {
				alert(data.message);
			}
		}, 'json');			
		
	});
	
	$('#deleteBook').bind('click', function(){
		check = confirm(PicBoard.languageMap.lang_321_confirmDeleteBook);
	
		if(check){	
			$.post(PicBoard.baseURL + "rsrc.php?req=deleteChart", { chartID: $('input#chID').val() }, function(data){
				if(data.statusCode == 200){
					window.location = "home";
				} else {
					alert(data.message);
				}
			}, 'json');	
		}
	});
	
	
	$('#publishBook').bind('click', function(){
		// We need to deep-check the book to see if it has any assets that cannot be published.
		
		$.post(PicBoard.baseURL + "rsrc.php?req=publishChart", { chartID: $('input#chID').val() }, function(data){
			alert(data.message);
		}, 'json');
	});
	
	$('#donateGroup').bind('click', function(){
		// We need to deep-check the book to see if it has any assets that cannot be published.
		
		$.post(PicBoard.baseURL + "rsrc.php?req=donateChartCheck", { chartID: $('input#chID').val(), groupID: $('select#donateSelector').val() }, function(data){
			if(data.statusCode == 200){
				$.post(PicBoard.baseURL + "rsrc.php?req=donateChart", { chartID: $('input#chID').val(), groupID: $('select#donateSelector').val() }, function(data){
					// Response from the server for request to donate
					if(data.statusCode == 200){
						jQuery.facebox.close();
						alert(data.message);
					} else {
						alert(data.message);
					}
				}, 'json');				
			} else if (data.statusCode == 207) {
				
				message = $("<div>", { style: 'text-align:center' });
				
				message.append( $("<h1>", { text: PicBoard.languageMap.lang_322_donateConfirm }) );
				message.append( $("<p>", { text: data.message }) );
				
				message.append(
					$("<button>", { text: PicBoard.languageMap.lang_51_yes, click: function(){
						// User has accepted the warning, send the request
						$.post(PicBoard.baseURL + "rsrc.php?req=donateChart", { chartID: $('input#chID').val(), groupID: $('select#donateSelector').val() }, function(data){
							// Response from the server for request to donate
							if(data.statusCode == 200){
								jQuery.facebox.close();
								alert(data.message);
							} else {
								alert(data.message);
							}
						}, 'json');
					} }),
					
					$("<button>", { text: PicBoard.languageMap.lang_52_no, click: function(){ jQuery.facebox.close() } })
				);
				
				
				// Display the message
				jQuery.facebox(message);
				
				$('button').button();
			}
		}, 'json');
	});
	
	$('#unDonate').bind('click', function(){
		if($('select#retrieveSelector').val() == "") return;
		$.post(PicBoard.baseURL + "rsrc.php?req=retrieveChart", { chartID: $('input#chID').val(), groupID: $('select#retrieveSelector').val() }, function(data){	
			if(data.statusCode == 200){
				// Remove the item from the select
				$('select#retrieveSelector').children("option:selected").remove();
				alert(data.message);
			} else {
				alert(data.message);
			}
		}, 'json');	
	});
	
	$('#copyChart').bind('click', function(){
		$.post(PicBoard.baseURL + "rsrc.php?req=copyChart", { bookID: $('input#bID').val(), newLocation: $('input[name=copyLocation]:checked').val(), newName: $('#newChartName').val() }, function(data){
			alert(data.message);
		}, 'json');
	});
	
	
	$('#groupSelector').bind('change', function(){
		window.location = "managebook?id=" + $(this).val();
	});
	
}

PicBoard.addLoadEvent( "setUp()" );